package com.lxw.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Config {

    public static final String EX_MEDIA_PROCESSTASK = "ex_media_processor";

    //视频处理队列
    @Value("${yh‐service‐manage‐media.mq.queue‐media‐video‐processor}")  
    public  String queue_media_video_processtask;
    //视频处理路由
    @Value("${yh‐service‐manage‐media.mq.routingkey‐media‐video}")
    public  String routingkey_media_video;

    // 声明路由模式交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(EX_MEDIA_PROCESSTASK);
    }
    @Bean
    public Queue postPageMq() {
        return new Queue(queue_media_video_processtask);//队列1
    }
    //
    @Bean
    public Binding dirBinding(DirectExchange directExchange, Queue postPageMq) {
        return BindingBuilder.bind(postPageMq).to(directExchange).with(routingkey_media_video);
    }
    public static final int DEFAULT_CONCURRENT = 10;

    @Bean("customContainerFactory")
    public SimpleRabbitListenerContainerFactory 
    containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, 
                     ConnectionFactory connectionFactory) {

        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(DEFAULT_CONCURRENT);
        factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT);
        configurer.configure(factory, connectionFactory);
        return factory;
    }
}
